<template>
  <header class="head-nav">
    <el-row>
      <el-col :span="6" class="logo-container">
        <img src="@/assets/img/logo.jpg" class="logo" alt="" />
        <span class="title">mulink在线后台管理系统</span>
      </el-col>
      <el-col :span="6" class="user-container">
        <div class="user">
          <img src="@/assets/img/logo.jpg" alt="test" class="avatar" />
          <div class="welcome">
            <p class="name comename">欢迎</p>
            <p class="name avatarname">{{ user.name }}</p>
          </div>
          <span class="username">
            <el-dropdown trigger="click" @command="setDialogInfo">
              <span class="el-dropdown-link">
                <i class="el-icon-caret-bottom el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="info">个人信息</el-dropdown-item>
                <el-dropdown-item command="logout">退出</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </span>
        </div>
      </el-col>
    </el-row>
  </header>
</template>

<script>
export default {
  name: "head-nav",
  computed: {
    user() {
      return this.$store.state.user;
    },
  },
  methods: {
    setDialogInfo(cmditem) {
      switch (cmditem) {
        case "info":
          this.showInfoList();
          break;

        case "logout":
          this.logout();
          break;
      }
    },
    showInfoList() {
      this.$router.push("/index/infoshow");
      // console.log("个人信息");
    },
    logout() {
      //清除token
      localStorage.removeItem("milink");
      //设置store
      this.$store.dispatch("clearCurrentState");
      //跳转
      this.$router.push("/login");
    },
  },
};
</script>

<style scoped>
.head-nav {
  width: 100%;
  height: 60px;
  min-width: 600px;

  background: #324057;
  color: #ffd04b;
  border-bottom: 1px solid #1f2d3d;
}
.logo-container {
  padding-top: 5px;
  padding-left: 20px;
}
.logo {
  width: 50px;
  border-radius: 25px;
  margin-right: 20px;
}

.user-container {
  height: 60px;
  float: right;
}

.title {
  vertical-align: 83%;
  font-size: 18px;
  font-family: "Microsoft YaHei";
}

.user {
  padding-right: 20px;
  text-align: right;
  display: flex;
  justify-content: right;
}

.avatar {
  width: 50px;
  height: 50px;
  margin-right: 20px;
  margin-top: 5px;
}

.welcome {
  height: 60px;
  line-height: 30px;
  margin-right: 10px;
}

.welcome .comename {
  font-size: 14px;
  text-align: center;
}
.welcome .avatarname {
  font-size: 12px;
  text-align: center;
  color: #3e90f7;
}
.username {
  line-height: 60px;
}

.el-dropdown-link {
  color: #fff;
}
</style>